﻿using System.IO;

namespace SuperCalculator
{
    /// <summary>
    /// 翻译单元, 负责数学表达式与CSharp表达式之间的转化等操作。
    /// </summary>
    internal class TranslateUnit
    {
        /// <summary>
        /// 将数学表达式转化为C#程序。
        /// </summary>
        /// <param name="express">用户输入的数学表达式。</param>
        /// <returns>返回C#程序。</returns>
        public static string TranslateToCSharp(string express)
        {
            var s = "";
            if (File.Exists(Function.GetPathOfFunctionDll()))
            {
                s += "using " + Function.FunctionNameSpace + ";\r\n";
            }

            s +=
             "using System;\r\n" +
             "namespace ComputeUnit\r\n" +
             "{\r\n" +
                "public class Compute\r\n" +
                "{\r\n" +
                "   public static double GetResult()\r\n" +
                "   {\r\n" +
                "      return " + TranslateToCSharpExpress(express) + ";\r\n" +
                "   }\r\n" +
                "}\r\n" +
            "}\r\n";
            return s;
        }

        /// <summary>
        /// 将数学表达式, 转化为C#表达式。
        /// </summary>
        /// <param name="mathExpress">数学表达式。</param>
        /// <returns></returns>
        private static string TranslateToCSharpExpress(string mathExpress)
        {
            //未完成的功能,TranslateToCSharpExpress
            return mathExpress;
        }
    }
}
